package com.kun.controller.admin;

import com.baomidou.mybatisplus.extension.api.R;
import com.kun.entity.Blog;
import com.kun.entity.BlogType;
import com.kun.entity.Blogger;
import com.kun.result.Result;
import com.kun.service.impl.BlogTypeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @descriptions: 博客类型管理后台
 * @author: SunKun
 * @date: 2021/7/6 0006 14:50
 * @version: 1.0
 */
@RestController
@CrossOrigin  //允许跨域
@ResponseBody
@RequestMapping("/kun/admin/blogType")
public class BlogTypeAdminController {
    @Autowired
    private BlogTypeServiceImpl blogTypeService;

    /**
     * 查看博客类别
     * @return
     * 在博客不存在的博客类型是不会显示的
     */
    @GetMapping("/queryBlogType")
    public Result queryBlogType(HttpServletRequest request, HttpServletResponse response){
        List<BlogType> blogTypes = null;
        try {
            blogTypes = blogTypeService.queryBlogTypeAndBlogCount();
            return Result.ok().data("blogTypes",blogTypes);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error();
        }
    }

    /**
     * 查看博客类型
     * @return
     */
    @GetMapping("/selectBlogType")
    public Result selectBlogType(){
        List<BlogType> blogTypes = blogTypeService.selectBlogType();
        return Result.ok().data("blogTypes",blogTypes);
    }
}
